import java.util.Vector;


public class Cashier extends Thread{
	public static long time = MY_PLACE.time;
	private static int totalCustomersServed = 0;
	private int customersServed = 0;
	Vector<Customer> customerQue = new Vector<Customer>();
	
	public Cashier (String id) {
		setName("Cashier-" + id);
	}

	public void msg(String m) {
		System.out.println("["+(System.currentTimeMillis()-time)+"] "+getName()+": "+m);
	}
	
	public void run(){
		msg("Cashier Thread has Started Running");
			
		try {
			do{
				if (customerQue.isEmpty()){
					sleep(10);
				} else {				
					Customer frontCustomer = customerQue.remove(0);
					acceptPayment(frontCustomer);
//					msg("" + frontCustomer);
//					msg("Payment taken from "+frontCustomer);
					customersServed++;
					totalCustomersServed++;
				}
			} while(totalCustomersServed < MY_PLACE.noOfCustomers);
		} catch (InterruptedException e) {
		}
	
		
		msg("*************************************");
		msg(getName()+" HAS TAKEN CARE OF ALL HIS/HER CUSTOMERS AND WAITING TO CLOSE");
		msg("*************************************");
	}

	public void acceptPayment( Customer customer ) {
		int randomNum;
		randomNum = 50 + (int)(Math.random() * (1000 - 50));
		try {
			sleep(randomNum);
			msg("Accepted payment from: "+customer);
		} catch (InterruptedException e) {
		}

		customersServed++;
		msg(" TOTAL CUSTOMERS SERVED = "+customersServed);
	}

	public void addToCue(Customer customer){
		
	}
	
/*	
	private String currentStock(){
		return("Brooms="+totalOfBrooms+"; Heads="+totalOfHeads+"; Torsos="+totalOfTorsos+"; Hands="+totalOfHands+"; Legs="+totalOfLegs);
	}
	
	private boolean isSurplus(String partType){
		int canBeUsedOfType = noOfLeastStockedPart; 		
		
		if (partType == "BROOM" && ((totalOfBrooms-canBeUsedOfType)>2))
			return true;
		else if (partType == "HEAD" && ((totalOfHeads-canBeUsedOfType)>2))
			return true;
		else if (partType == "TORSO" && ((totalOfTorsos-canBeUsedOfType)>2))
			return true;
		else if (partType == "HAND" && (((totalOfHands/2)-canBeUsedOfType)>2))
			return true;
		else if (partType == "LEG" && (((totalOfLegs/2)-canBeUsedOfType)>2))
			return true;
		else return false;

	}
	
	private void updateInventory(String partType){
		if (partType == "BROOM")
			totalOfBrooms++;
		else if (partType == "HEAD")
			totalOfHeads++;
		else if (partType == "TORSO")
			totalOfTorsos++;
		else if (partType == "HAND")
			totalOfHands++;
		else if (partType == "LEG")
			totalOfLegs++;
		updateMinOfStock();
	}
	
	private void updateMinOfStock(){
		int minNo = totalOfBrooms;
		
		if (totalOfHeads < minNo)
			minNo = totalOfHeads;
		if (totalOfTorsos < minNo)
			minNo = totalOfTorsos;
		if ((totalOfHands/2) < minNo)
			minNo = (totalOfHands/2);
		if ((totalOfLegs/2) < minNo)
			minNo = (totalOfLegs/2);
		
		noOfLeastStockedPart = minNo;
	}
	
	private void assembleSCrow() {
		int randomNum;
		randomNum = PRODUCTION_TIME_MIN + (int)(Math.random() * ((PRODUCTION_TIME_MAX - PRODUCTION_TIME_MIN) + 1));

		try {
			sleep(randomNum);
			totalOfBrooms--;
			totalOfHeads--;
			totalOfTorsos--;
			totalOfHands-=2;
			totalOfLegs-=2;

			sCrowCount++;
			msg("SCAREROW # " + sCrowCount + " ASSEMBLED");
		} catch (InterruptedException e) {
		}
	}
*/
}
